package com.example.androidcomplete0102.ch11;


import com.example.androidcomplete0102.R;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.ToggleButton;
import android.widget.RadioGroup.OnCheckedChangeListener;

public class RadioCheck extends Activity {
TextView mText;
	
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch11_radiocheck);
		mText = (TextView) findViewById(R.id.ch11_txtsample);
		
		RadioGroup colGroup = (RadioGroup) findViewById(R.id.ch11_colorgroup);
		colGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			public void onCheckedChanged(RadioGroup group, int checkedId) {
				if (group.getId() == R.id.ch11_colorgroup){
					switch(checkedId){
					case R.id.ch11_rared:
						mText.setTextColor(Color.RED);
						break;
					case R.id.ch11_ragreen:
						mText.setTextColor(Color.GREEN);
						break;
					case R.id.ch11_rablue:
						mText.setTextColor(Color.BLUE);
						break;
					}
				}				
			}
		});
		
		CheckBox chkWhite = (CheckBox) findViewById(R.id.ch11_chkwhiteback);
		ToggleButton tglLang = (ToggleButton) findViewById(R.id.ch11_tgllanguage);
		
		chkWhite.setOnCheckedChangeListener(mListener);
		tglLang.setOnCheckedChangeListener(mListener);
	}

	CompoundButton.OnCheckedChangeListener mListener = new CompoundButton.OnCheckedChangeListener() {
		public void onCheckedChanged(CompoundButton buttonView,	boolean isChecked) {
			if (buttonView.getId()==R.id.ch11_chkwhiteback){
				if (isChecked){
					mText.setBackgroundColor(Color.BLACK);
				}else{
					mText.setBackgroundColor(Color.TRANSPARENT);
				}
			}
			if (buttonView.getId()==R.id.ch11_tgllanguage){
				if (isChecked){
					mText.setText("샘플");
				}else{
					mText.setText("Sample");
				}
			}
		}
	};
}
